package com.nhim.cms.util;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nhim.cms.dao.CustomWidgetDAO;
import com.nhim.cms.domain.CustomWidget;

@Service
public class CustomWidgetManager {
	
	@Autowired
	CustomWidgetDAO customWidgetDAO;
	
	@PostConstruct
	public void init() throws Exception {
	}

	@PreDestroy
	public void destroy() {
	}
	
	@Transactional(readOnly = true)
	public List<CustomWidget> findCustomWidgetEntriesBySearch(
			String startsWith, String orderBy) {
		return customWidgetDAO.findCustomWidgetEntriesBySearch(startsWith, orderBy);
	}

	@Transactional(readOnly = true)
	public Integer countCustomWidgetBySearch(String startsWith) {
		return customWidgetDAO.countCustomWidgetBySearch(startsWith);
	}

	public static CustomWidgetManager getFromApplicationContext(
			ApplicationContext ctx) {
		return (CustomWidgetManager) ctx
				.getBean(CustomWidgetManager.class);
	}
}
